﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using System.Diagnostics;

namespace Algorithms.Expressions
{
    public class ConstantExpressionFactory : IExpressionFactory
    {
        #region Fields 

        private readonly string _name;
        private readonly Expression _expression;

        #endregion // Fields 

        #region Constructor 

        public ConstantExpressionFactory(string name, double value)
            : this(name, Expression.Constant(value, typeof(double)))
        {
        }

        public ConstantExpressionFactory(string name, Expression expression)
        {
            if (string.IsNullOrEmpty(name))
                throw new ArgumentException("name");
            if (expression == null)
                throw new ArgumentNullException("exception");

            _name = name;
            _expression = expression;
        }

        #endregion // Constructor 

        #region Properties

        public int RequiredArgumentLength { get { return 0; } }

        public string Name
        {
            get { return _name; }
        }

        #endregion // Properties

        #region Methods 

        public Expression Create(IEnumerable<Expression> arguments)
        {
            Debug.Assert(arguments.Count() == RequiredArgumentLength);

            return _expression;
        }

        #endregion // Methods
    }
}
